# user/serializer.py

from rest_framework import serializers

from menu.models import Menu

class NextMenuSerializer(serializers.ModelSerializer):

	class Meta:
		model = Menu
		fields = ('id', 'name', 'icon', 'url')

class MenuSerializer(serializers.ModelSerializer):
	children = serializers.SerializerMethodField()

	def get_children(self, obj):
		children = obj.menu_set.all()
		return NextMenuSerializer(instance=children, many=True).data

	class Meta:
		model = Menu
		fields = ('id', 'name', 'icon', 'url', 'children')